<?php
    @session_start();
    
    include_once('app/connection.php');
    include_once('app_sv/check_user.php');
    
    
?>

<style>
    .danhsach tr:first-child{background: #247CB9;}
</style>

<?php    
    if($is_sv)
    {
                
    
?>
        <div style="width: 720px; min-height: 400px; overflow-y: scroll; margin: 0 auto;">
            <form name="dkmh" method="POST" action="">
            <center><table class="danhsach">
            
                <tr style="background: #247CB9;">
                    <td style="text-align: center; color: #fff;">Mã HP</td>
                    <td style="text-align: center; color: #fff;">Tên Học phần</td>
                    <td style="text-align: center; color: #fff;">Tín chỉ</td>
                    <td style="text-align: center; color: #fff;">Điểm GK</td>
                    <td style="text-align: center; color: #fff;">Điểm TH</td>
                    <td style="text-align: center; color: #fff;">Điểm CK</td>
                    <td style="text-align: center; color: #fff;">Điểm HP</td>
                </tr>
<?php
        $sql1 = mysql_query("SELECT ketqua.HOCKY, NAM, SUM(TINCHILYTHUYET + TINCHITHUCHANH) AS TONGTINCHI, 
        TRUNCATE(SUM(DIEMTRUNGBINH * (TINCHILYTHUYET + TINCHITHUCHANH))/SUM(TINCHILYTHUYET + TINCHITHUCHANH),2) AS TRUNGBINHHK 
        FROM KETQUA, MONHOC WHERE ketqua.MAMONHOC = monhoc.MAMONHOC AND MSSV = '".$_SESSION['s_user']."'
        GROUP BY ketqua.HOCKY, NAM");
        while($rows1 = mysql_fetch_assoc($sql1)) {
            echo '<tr>';
            echo "<td colspan='7'><center><b><i>Học kỳ ".$rows1['HOCKY']." - năm ".$rows1['NAM']."</i></b></center></td></tr>";
            
            $hocky = $rows1['HOCKY'];
            $nam = $rows1['NAM'];
            
            $sql2 = mysql_query("SELECT (TINCHILYTHUYET + TINCHITHUCHANH) AS TINCHI, ketqua.MAMONHOC, TENMONHOC,
            DIEMTHUCHANH, DIEMGIUAKY, DIEMCUOIKY, DIEMTRUNGBINH FROM ketqua, monhoc WHERE ketqua.MAMONHOC = monhoc.MAMONHOC 
            AND ketqua.HOCKY = $hocky AND NAM = '$nam' AND MSSV = '".$_SESSION['s_user']."' ORDER BY NAM, ketqua.HOCKY");
            
            while($rows2 = mysql_fetch_assoc($sql2)) {
                 echo "<tr>";
                 echo "<td>".$rows2['MAMONHOC']."</td>";
                 echo "<td>".$rows2['TENMONHOC']."</td>";
                 echo "<td>".$rows2['TINCHI']."</td>";
                 echo "<td>".$rows2['DIEMGIUAKY']."</td>";
                 echo "<td>".$rows2['DIEMTHUCHANH']."</td>";
                 echo "<td>".$rows2['DIEMCUOIKY']."</td>";
                 echo "<td>".$rows2['DIEMTRUNGBINH']."</td>";
                 echo "</tr>";  
            }
            
            echo "<tr><td></td>";
            echo "<td><b><i>Trung bình học kỳ</i></b></td>";
            echo "<td><b><i>".$rows1['TONGTINCHI']."</i></b></td>";
            echo "<td></td> <td></td> <td></td>";
            echo "<td><b><i>".$rows1['TRUNGBINHHK']."</i></b></td></tr>";
        }
?>
        </table></center>
        </form>
        </div>
<?php
    }
	else
	{
		echo "Bạn không được phép xem trang nay!";
		echo "<meta http-equiv=\"refresh\" content=\"1; URL=index.php\">";
	}
?>